1 using UnityEngine;
2 using
System.Collections;
3
4
5
6 public
struct GoSmoothedVector3
7 {
8     
public GoSmoothingType smoothingType;
9     
public float duration;
10     
11     
private Vector3 _currentValue;
12     
private Vector3 _target;
13     
private Vector3 _start;
14     
private float _startTime;
15     
16     
17     
public GoSmoothedVector3( Vector3 vector )
18     {
19         _currentValue = vector;
20         _start = vector;
21         _target = vector;
22         _startTime = Time.time;
23         
24         
// set sensible defaults
25         duration =
0.2f;
26         smoothingType = GoSmoothingType.Lerp;
27     }
28     
29     
30     
public Vector3 smoothValue
31     {
32         
get
33         {
34             
// how far along are we?
35             
var t = ( Time.time - _startTime ) / duration;
36             
37             
switch( smoothingType )
38             {
39                 
case GoSmoothingType.Lerp:
40                     _currentValue = Vector3.Lerp( _start, _target, t );
41                     
break;
42                 
case GoSmoothingType.Slerp:
43                     _currentValue = Vector3.Slerp( _start, _target, t );
44                     
break;
45             }
46             
47             
return _currentValue;
48         }
49         
private set
50         {
51             _start = smoothValue;
52             _startTime = Time.time;
53             _target =
value;
54         }
55     }
56     
57     
58     
public float x
59     {
60         
get
61         {
62             
return _currentValue.x;
63         }
64         
set
65         {
66             smoothValue =
new Vector3( value, _target.y, _target.z );
67         }
68     }
69     
70     
public float y
71     {
72         
get
73         {
74             
return _currentValue.y;
75         }
76         
set
77         {
78             smoothValue =
new Vector3( _target.x, value, _target.y );
79         }
80     }
81     
82     
public float z
83     {
84         
get
85         {
86             
return _currentValue.z;
87         }
88         
set
89         {
90             smoothValue =
new Vector3( _target.x, _target.y, value );
91         }
92             
93     }
94     
95     
96     
public static implicit operator GoSmoothedVector3( Vector3 v )
97     {
98         
return new GoSmoothedVector3( v );
99     }
100     
101 }



Trò chơi Angry Birds trong UNITY Engine 31.661 lượt xem

Gõ tìm kiếm nhanh...